# # 随机次数
# import random
#
#
# def main():
#     count = 0
#     l = []
#     while True:
#         n = random.randint(100, 200)
#         count += 1
#         if n not in l:
#             l.append(n)
#             if len(l) == 50:
#                 break
#
#     print(count)
#
#
# main()
#
#
# # 斐波那契数列：1，1，2，3，5，8，13，21，34，55，89...
#
#
# def main(n):
#     l = [1, 1]
#     while True:
#         l.append(l[-1] + l[-2])
#         if len(l) == n:
#             break
#     # print(l, len(l), l[n - 1])
#     print(f"第{n}个数是{l[-1]}")
#
#
# n = int(input("请输入一个数"))
#
# main(n)

# 年纪升序  学号降序
import random


class Student:
    def __init__(self, sid, name):
        self.sid = sid
        self.name = name
        self.age = random.randint(18, 24)

    def __str__(self):
        return f"学生学号:{self.sid}  学生姓名:{self.name}  学生年纪：{self.age}"


def main():
    l = []
    ll = ["赵大", "王二", "张三", "李四", "吆五", "喝六", "妖七", "刘八", "朱九", "裴十"]
    for i in range(10):
        s = Student(101 + i, f"{ll[i]}")
        l.append(s)

    for i in range(len(l) - 1):
        max_index = i
        for j in range(i + 1, len(l)):
            if l[j].age < l[max_index].age:
                max_index = j

        if max_index != i:
            age = l[max_index]
            l[max_index] = l[i]
            l[i] = age

    for i in range(len(l)-1):
        for j in range(i+1, len(l)):
            if l[i].age == l[j].age and l[i].sid < l[j].sid:
                    sid = l[j]
                    l[j] = l[i]
                    l[i] = sid

    for s in l:
        print(s)


main()


# 装饰器统计时间开销
import time
import random


def a(f):
    def b():
        start = time.time()
        print(f"函数开始执行")
        f()
        print(f"函数执行结束  花费时间{time.time()-start}")
    return b


@a
def speed_time():
    l = []
    for i in range(5):
        n = random.randint(5, 10)
        l.append(n)
        time.sleep(1)
    print(l)


speed_time()

# 选择排序

l = [5, 9, 5, 2, 8, 6]


for i in range(len(l) - 1):
    max_index = i
    for j in range(i + 1, len(l)):
        if l[j] > l[max_index]:
            max_index = j

    if max_index != i:
        temp = l[i]
        l[i] = l[max_index]
        l[max_index] = temp
print(l)


# 二维数组列的最大值
l = [
    [1, 2, 3, 10],
    [4, 50, 6, 7],
    [70, 8, 9, 5]
]

for i in range(4):
    max_num = l[0][i]
    for j in range(3):
        if max_num < l[j][i]:
            max_num = l[j][i]

    print(max_num)
